﻿<cfcomponent>

<cfscript>
DB = 'chinalaohu';
</cfscript>
<cfparam name="UUID" default="0" type="string" >

<!---个人信息接口--->
<cffunction name="show" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
  <cfinvoke method="usershow" returnvariable="usershow" uuid="#uuid#" />
  
  <cfif usershow.recordcount gt 0>
  	<cfinvoke component="userbank" method="defaultbank" returnvariable="defaultbank" uid="#usershow.uid#" />
  	<cfinvoke component="useraddresses" method="defaultaddr" returnvariable="defaultaddr" uid="#usershow.uid#" />
		<cfscript>
		if (defaultbank.recordcount gt 0){
			bank = defaultbank.cardno;
		}
		else {
			bank = '';
		}
		if (defaultaddr.recordcount gt 0){
			address = defaultaddr.province & defaultaddr.city & defaultaddr.district & ' ' & defaultaddr.street;
		}
		else {
			address = '';
		}
		//姓名是否已经填过
		if(len(usershow.realname) gt 1){
			n_auth = 1;
		}
		else {
			n_auth = 0;
		}	
		
		j = {"success":"1",
		"verify":{
			"name":n_auth,
			"card":usershow.i_auth,
			"email":usershow.e_auth
		},
		"perfectInfo":{
			 "realName": usershow.realname,
			 "birthday": dateformat(usershow.birthday,'yyyy-mm-dd'),
			 "cardType": usershow.idtype,
			 "cardList":["身份证"],
			 "cardNumber": usershow.idnumber,
			 "email": usershow.email,
			 "bank":bank,
			 "address":address,
			 "hobby":""
		 }
		};
    </cfscript>
  <cfelse>
    <cfscript>
		j = {"success":"0","errCode":"0"};
		</cfscript>
  </cfif>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
  </cfscript>
</cffunction>

<!---更新个人信息接口--->
<cffunction name="update" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
  <cfquery datasource="#DB#" result="rs">
  update user_base set
  <cfif isdefined('realname')>realname = '#realname#',</cfif>
  <cfif isdefined('sex')>sex = #sex#,</cfif>
  <cfif isdate(birthday)>birthday = '#birthday#',</cfif>
  idtype = '#cardType#',  
  IDnumber = '#cardNumber#',
  email = '#email#'
  where muuid = '#UUID#'
  </cfquery>
  <cfscript>
	if (rs.recordcount gt 0){
		j = {"success":"1"};
	}
	else {
		j = {"success":"0","errCode":"0"};
	}
  </cfscript>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>
</cffunction>





<cffunction name="usershow" access="public" returntype="query">
	<cfquery datasource="#DB#" name="usershow">
  select *
  from user_base
  where muuid = '#uuid#'
  limit 1
  </cfquery>
  <cfreturn usershow >
</cffunction>
  
  
</cfcomponent>

